package thread1;

public class Demo5 {
    public static void main(String[] args) throws InterruptedException {
        Thread thread = new Thread(() -> {
            while(!Thread.currentThread().isInterrupted()){
                System.out.println("线程进行");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
//                    e.printStackTrace();
//                    break;
                }
            }
        });

        thread.start();
        Thread.sleep(4000);  //主线程休眠
        System.out.println("终止 thread 线程");
        thread.interrupt();
    }
}
